#!/usr/bin/env python3.10
# -*- encoding: utf-8 -*-
'''
@File    :   schemas.py
@Time    :   2023/09/05 17:48:25
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib
from ninja import Schema, Field, ModelSchema
from apps.user.models import AddressBook

class SendMsgSchema(Schema):
    phone: str = Field(..., description="手机号", regex=r'^1[3456789]\d{9}$')


class SendMsgResultSchema(Schema):
    code: str = Field(..., description="验证码")
    
class UserLoginSchema(SendMsgSchema, SendMsgResultSchema):
    pass


class AddressBookSchema(ModelSchema):
    # 兼容H5
    sex: str
    # h5使用的是 isDefault；这里与数据库字段is_default做一个映射
    isDefault: int = Field(..., alias="is_default")

    class Config:
        model = AddressBook
        model_fields = "__all__"


class AddressBookCreateSchema(ModelSchema):
    """
    {
    "consignee": "XXX",
    "phone": "XXXXXXX",
    "sex": "1",
    "detail": "XXXXXXXX",
    "label": "XXXXXXX"
}
    """

    class Config:
        model = AddressBook
        model_fields = ['consignee', 'phone', 'sex', 'detail', 'label']


class AddressBookSetDefaultSchema(Schema):
    id: int